// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: 'nodejs-zyvej',
  traceUser: true,
})
const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async(event, context) => {
  console.log(event.concertid.length)
  try {
    if (event.concertid.length == 0) {
      return await db.collection('tickets').where({
        userid: event.userid
      }).get();
    } else {
      return await db.collection('tickets').where({
        userid: event.userid,
        concertid: _.in(event.concertid)
      }).get();
    }
  } catch (e) {
    console.error(e);
  }

}